package com.qinggeng.project.system.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.Position;
import com.qinggeng.project.system.service.IPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 招聘职位管理Controller
 *
 * @author smallfish
 * @date 2020-11-125
 */
@RestController
@RequestMapping("/system/position")
public class PositionController extends BaseController
{
    @Autowired
    private IPositionService positionService;

    /**
     * 查询招聘职位管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:position:list')")
    @GetMapping("/list")
    public TableDataInfo list(Position position)
    {
        startPage();
        List<Position> list = positionService.listPosition(position);
        return getDataTable(list);
    }

    /**
     * 导出招聘职位管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:position:export')")
    @Log(title = "招聘职位管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Position position)
    {
        List<Position> list = positionService.listPosition(position);
        ExcelUtil<Position> util = new ExcelUtil<Position>(Position.class);
        return util.exportExcel(list, "position");
    }

    /**
     * 获取招聘职位管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:position:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(positionService.getPositionById(id));
    }

    /**
     * 新增招聘职位管理
     */
    @PreAuthorize("@ss.hasPermi('system:position:add')")
    @Log(title = "招聘职位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Position position)
    {
        return toAjax(positionService.insertPosition(position));
    }

    /**
     * 修改招聘职位管理
     */
    @PreAuthorize("@ss.hasPermi('system:position:edit')")
    @Log(title = "招聘职位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Position position)
    {

        return toAjax(positionService.checkPosition(position));
    }

    /**
     * 删除招聘职位管理
     */
    @PreAuthorize("@ss.hasPermi('system:position:remove')")
    @Log(title = "招聘职位管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(positionService.deletePositionByIds(ids));
    }
}
